<?php
/**
 * Created by PhpStorm.
 * User: geek
 * Date: 16/4/8
 * Time: 下午11:06
 */
error_reporting(0);
header("Content-Type","text/html;charset=utf-8");
require_once '../model/PdoMySQL.class.php';
require_once '../model/config.php';
require_once '../model/pwd.php';
if (!isset($_POST["username"]) || empty($_POST["username"])
    || !isset($_POST["password"]) || empty($_POST["password"])
    || !isset($_POST["email"]) || empty($_POST["email"])
    || !isset($_POST["projecterHandler"]) || empty($_POST["projecterHandler"])|| !isset($_POST["currentUsername"]) || empty($_POST["currentUsername"])) {
    echo '<script language="JavaScript">window.alert("参数错误,用户信息不完整"),location.href="../view/profile.php";</script>';
    return;
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
    update();
}
function update(){
    if (!isset($_POST["username"]) || empty($_POST["username"])
        || !isset($_POST["password"]) || empty($_POST["password"])
        || !isset($_POST["email"]) || empty($_POST["email"])
        || !isset($_POST["projecterHandler"]) || empty($_POST["projecterHandler"])) {
        echo "参数错误,用户信息不完整";
        return;
    }else{
        $username=$_POST["username"];
        $password=base64_encode($_POST["password"]);
        $email=$_POST["email"];
        $projecterHandler=$_POST["projecterHandler"];
        $currentUsername=$_POST["currentUsername"];
        $pdo=new PdoMySQL();
        $sql="UPDATE projector SET username='{$username}',password='{$password}',email='{$email}',projectername='{$projecterHandler}' WHERE  username='{$currentUsername}' ";
        $stmt=$pdo->query($sql);
        if($stmt=='1'){
            $_SESSION["username"]=$username;
            $_SESSION["password"]=$password;
           // echo '<script language="JavaScript">window.alert("用户信息修改成功"),location.href="../view/profile.php";</script>';
            $pdo1=new PdoMySQL();
//            $sql1="INSERT INTO sessionTab (username) VALUES ('"."{$_SESSION["username"]}"."')";
            $sql1="UPDATE sessionTab SET username='".$_SESSION["username"]. "'  WHERE  username='{$currentUsername}' ";
            $stmt1=$pdo1->query($sql1);
            if( $stmt1=='1'){
               echo "用户信息修改成功";
            }else{
                echo "请再尝试";
            }
        }else{
            //echo '<script language="JavaScript">window.alert("用户信息修改失败"),location.href="../view/profile.php";</script>';
            echo "用户信息修改失败";
        }
    }
}

?>




